package com.zhixiang.core.service.impl;


import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.dao.BaseDao;
import com.zhixiang.core.entity.TreeObj;
import com.zhixiang.core.service.BaseService;
import com.zhixiang.core.web.paging.PagingBean;


public abstract class BaseServiceImpl<T, PK extends Serializable> implements BaseService<T, PK>
{
    @SuppressWarnings("unchecked")
    protected Log logger = LogFactory.getLog((Class<T>)((ParameterizedType)getClass() // Class字节码
    .getGenericSuperclass()) // 因为对于T.class我们无法获取，但是这个方法就能获取到父类的参数类型，返回值为ParameterizedType
    .getActualTypeArguments()[0]);

    private BaseDao<T, PK> dao;

    public abstract void setBaseDao(BaseDao<T, PK> dao);

    public BaseDao<T, PK> getDao()
    {
        return dao;
    }

    public void setDao(BaseDao<T, PK> dao)
    {
        this.dao = dao;
    }

    public T get(PK pk)
    {
        return this.dao.get(pk);
    }

    public T save(T obj)
    {
        return this.dao.save(obj);
    }

    public T merge(T obj)
    {
        return this.dao.merge(obj);
    }

    public void evict(T obj)
    {
        this.dao.evict(obj);
    }

    public List<T> getAll()
    {
        return this.dao.getAll();
    }

    public List<T> getAll(PagingBean pagingbean)
    {
        return this.dao.getAll(pagingbean);
    }

    public List<T> getAll(QueryFilter queryfilter)
    {
        return this.dao.getAll(queryfilter);
    }

    public void remove(PK[] pks)
    {
        for (PK pk : pks)
        {
            this.dao.remove(pk);
        }
    }

    public void remove(T obj)
    {
        this.dao.remove(obj);
    }

    public void flush()
    {
        this.dao.flush();
    }
    
    
    @Override
    public T uniqueResult(String queryString, Object[] values)
    {
       
        return dao.uniqueResult(queryString, values);
    }
    

    @Override
    public Long update(String paramString, Object[] paramArrayOfObject)
    {
        return dao.update(paramString, paramArrayOfObject);
    }

    public List<TreeObj> getTreeObj(PK id , String displayName,Map<String,String> map){
        return this.dao.getTreeObj(id , displayName, map);
    }
}
